package com.chixing.day09_innerclass;

public class StringDemo {
    public static void main(String[] args) {
        String s1 = "hello";
        s1 = "good";
        System.out.println(s1);

        String s2 = new String("code"); // 堆
        String s3 = "code";     //字符串常量池
        System.out.println("s2== s3? :" + (s2 == s3)); // false

        String s4 =  "file";
        String s5 =  "file";
        System.out.println("s4== s5? :" + (s4 == s5)); // true == 比较的是内存地址


        String s6 = new String("help");
        String s7 = new String("help");
        System.out.println("s6== s7? :" + (s6 == s7)); //false
        String s8 = "help";

        /**
         * String s1 ="a";
         * String s2 ="b";
         *
         *   s1+s2 ===> new String("ab") 堆
         *   s1.concat(s2) ===> new String("ab") 堆
         *
         *   "a" + "b" ===>在常量池中 放一份"ab"
         *
         *
         */
        String str1 = "hello";
        String str2 = "world";
        String str3 = str1 + str2;  // new String("helloworld")
        String str4 = "helloworld";
        System.out.println("str3 == str4 :" + (str3 == str4)); //false


        String str0 = "hello" + "world"; // "helloworld" 到常量池中匹配
        System.out.println("str0 == str4 :" + (str0 == str4)); // true


        String str5 = str1 + str2; // new String("helloworld")
        System.out.println("str3 == str5 :" + (str3 == str5)); //false

        String str6 = str1.concat(str2); // new String( "helloworld")
        System.out.println("str3 == str6 :" + (str3 == str6));


        str0.indexOf('e');
        String xx = str0.substring(0,5);// "Returns a string resulting"
    }
}
